package name.ekr.edu.threads.chatserver.client;

import java.io.BufferedReader;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import name.ekr.edu.threads.chatserver.Server;

public class ReaderClient extends Thread {
	static Logger logger = LoggerFactory.getLogger(ReaderClient.class);
	private Server server;
	private BufferedReader consoleReader;
	
	public ReaderClient(Server server, BufferedReader consoleReader) {
		this.server = server;
		this.consoleReader = consoleReader;
	}

	public void run() {
		String consoleInput = null;
		do {
			try {
				consoleInput = consoleReader.readLine();
				server.sendMessage(consoleInput);
			} catch (IOException e) {
				logger.error("", e);
				throw new RuntimeException("Communication error", e);
			}
		} while(!"quit".equals(consoleInput));
	}
}
